import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import { intl, moneyFormatCol, nanoid10 } from "@/utils";
import { Button, CheckBox, DataGrid, NumberBox, Popup, SelectBox, TextBox } from 'devextreme-react';
import { CpasIcon, DevGrid, DevToolBar, LayoutB } from '~/public/cpas-ui';
import { Column, Editing, Item, Lookup, Paging, Selection, Summary, Toolbar, TotalItem } from 'devextreme-react/data-grid';
import './index.less';
import { Button as TextBoxButton } from 'devextreme-react/text-box';
import { columnsDataMQW, columnsDataMQW2, columnsDataMQW2_1, columnsDataMQW2_2, columnsDataMQW2_3 } from './tableColumnData';
import { conditionsColumnData, conditionStatesData } from '../conditionalQueryTableList/tableColumnData';
import { Typography } from 'antd';
import AdvancedQueryPupop from '../advancedQueryPupop';
import { useModel } from 'umi';
import { getChangeApiNameData } from '../service';
import SubjectPopup from '~/public/cpas-business/components-bs/SubjectPopup';
import AccountingVoucherPupop from '../accountingVoucherPupop';
import { msgInfo } from '@/utils/msg';
import { ClearOutlined } from '@ant-design/icons';
import notify from 'devextreme/ui/notify';
// import PageLoading from '@/pages/components/PageLoading';


const { Text } = Typography;

const CertificateListPupop = React.forwardRef((props: any, ref: any) => {
    const { initialState } = useModel('@@initialState');

    const { dbname, sjnd } = initialState?.curPart as any;
    const { username } = initialState?.curUser as any;

    const [visible, setVisible] = useState<boolean>(false);
    const popupRef = useRef<any>(null);
    // const [spinLoad, setSpinLoad] = useState<boolean>(true);
    // const dataGridRef = useRef<any>(null);
    const accountingVoucherPupopRef = useRef<any>(null);

    const [changeKey, setChangeKey] = useState<string>('sdas');


    const devGridRef = useRef<any>(null);
    const SubjectRef = useRef<any>();

    const queryPupopRef = useRef<any>(null);
    const [dataGridData, setDataGridData] = useState<any[]>([]);
    const [queryData, setQueryData] = useState<string>('');
    // const [checkContent, setCheckContent] = useState<boolean>(false);
    const [pupopTitleText, setPupopTitleText] = useState<string>('会计凭证列表');
    const [openPpupopType, setOpenPpupopType] = useState<string>('1');
    const openPpupopTypeRef = useRef<string>('1');

    const [paramsQueryData, setparamsQueryData] = useState<string>('');
    const advancedQueryPupopRef = useRef<any>(null);

    const [searchParams, setSearchParams] = useState<any>({
        yearID: '',
        checkQueryContent: true,
        xswzpzCheck: false,
        jefsID: 0,
        PZCYStart: '',
        PZCYEnd: '',
        jeStart: '',
        jeEnd: '',
        kmmcStr: '',
        dfkmmcStr: '',
        zyStr: '',
    });

    const onCancel = () => {
        setDataGridData([]);
        setSearchParams({
            yearID: '',
            checkQueryContent: true,
            xswzpzCheck: false,
            jefsID: 0,
            PZCYStart: '',
            PZCYEnd: '',
            jeStart: '',
            jeEnd: '',
            kmmcStr: '',
            dfkmmcStr: '',
            zyStr: '',

        })
        setVisible(false);
    }

    const searchFunction = async (allParams: any, queryDataParams: any) => {
        const { yearID, checkQueryContent, xswzpzCheck, PZCYStart, PZCYEnd, jeStart, jeEnd, kmmcStr, dfkmmcStr, zyStr } = allParams;

        // setTreeSelecNode((oldData: any) => {
        //     let newData: any = { ...oldData }
        //     newData.spinLoad = true;
        //     return newData;
        // });

        // setSpinLoad(true);

        let allSqlText = '';
        let jeSqlText = '';
        let PZCYSqlText = '';
        let kmmcSqlText = '';
        let dfkmSqlText = '';
        let zySqlText = '';

        if (jeStart > 0 && jeEnd > 0) {
            jeSqlText = `and ( ABS( isnull(JFJE,0)+ isnull(DFJE,0)) BETWEEN ${jeStart} and ${jeEnd})`;
        } else {
            if (jeStart > 0) {
                jeSqlText = `and ( ABS( isnull(JFJE,0)+ isnull(DFJE,0)) >=${jeStart})`;
            } else if (jeEnd > 0) {
                jeSqlText = `and ( ABS( isnull(JFJE,0)+ isnull(DFJE,0)) <= ${jeEnd})`;
            }
        }
        if (PZCYStart > 0 && PZCYEnd > 0) {
            PZCYSqlText = `and (Diff BETWEEN ${PZCYStart} and ${PZCYEnd})`;
        } else {
            if (PZCYStart > 0) {
                PZCYSqlText = `and ( Diff >=${PZCYStart})`;
            } else if (PZCYEnd > 0) {
                PZCYSqlText = `and ( Diff <= ${PZCYEnd})`;
            }
        }

        if (kmmcStr) {
            let stringArray = kmmcStr.split(',');
            // and ( KMMC like '%库存现金%' Or  KMMC like '%银行存款%' Or  KMMC like '%银行存款-建行纳税户%')
            stringArray.forEach((item: any, index: number) => {
                if (index === 0) {
                    kmmcSqlText = `and (KMMC like '%${item}%'`;
                } else {
                    kmmcSqlText = kmmcSqlText + ` or KMMC like '%${item}%'`;
                }
            });
            kmmcSqlText = kmmcSqlText + ')';

        }
        if (dfkmmcStr) {
            let stringArray = dfkmmcStr.split(',');
            // and ( DFKMMC like '%库存现金%' Or  DFKMMC like '%银行存款%' Or  DFKMMC like '%银行存款-建行纳税户%')
            stringArray.forEach((item: any, index: number) => {
                if (index === 0) {
                    dfkmSqlText = `and (DFKMMC like '%${item}%'`;
                } else {
                    dfkmSqlText = dfkmSqlText + ` or DFKMMC like '%${item}%'`;
                }
            });
            dfkmSqlText = dfkmSqlText + ')';

        }

        if (zyStr) {
            zySqlText = `and(ZY Like '%${zyStr}%')`;
        }

        allSqlText = `${jeSqlText}${kmmcSqlText}${dfkmSqlText}${zySqlText} ${checkQueryContent ? queryDataParams : ''}`;

        let apiNameTemp = 'account.PZB.getVoucherDetailList';

        if (openPpupopTypeRef.current === '1') {
            apiNameTemp = 'account.PZB.getVoucherBillList';
        } else {
            apiNameTemp = 'account.PZB.getVoucherDetailList';
        }


        const res: any = await getChangeApiNameData(apiNameTemp, {
            dbname,
            Data_ID: yearID,
            otherWhere: allSqlText,
            otherWhere2: PZCYSqlText,
            displayOption: xswzpzCheck
        });
        if (res.success) {
            if (res.data.length > 0) {
                setDataGridData(res.data);
            } else {
                setDataGridData([]);
            }
            const scrollableSet = devGridRef?.current?.instance?.getScrollable();
            scrollableSet?.scrollTo({ top: 0 });
            // setSpinLoad(false);
        } else {
            setDataGridData([]);
            // setSpinLoad(false);

        }
    }

    //  修改基本的参数
    const changeData = (valKey: string, val: any, valType: string = 'paramsData') => {
        setSearchParams((oldData: any) => {
            let newData = { ...oldData };
            newData[valKey] = val;
            if (valType === 'query') {
                searchFunction(newData, paramsQueryData);
            }
            return newData;
        })
    };





    // 自定义方法
    useImperativeHandle(ref, () => ({
        showPupop: async (propsData: any) => {
            const { yearID, rowData, pupopType, changeNodeKey, columnName, pupopTabsType } = propsData;

            setChangeKey(nanoid10());

            queryPupopRef.current = rowData;
            setPupopTitleText(pupopType === '1' ? '会计凭证列表' : '会计分录列表');
            setOpenPpupopType(pupopType);
            openPpupopTypeRef.current = pupopType;
            // setCheckContent(true);
            let queryDataText = ' ';
            let paramsQueryDataText = ' ';

            if (changeNodeKey === '0-0-0') {
                queryDataText = '凭证月份 等于 ' + rowData.PZYF + ' 且存在差异的凭证';
                paramsQueryDataText = `and (PZYF = ${rowData.PZYF})`;

            } else if (changeNodeKey === '0-0-0-0') {
                if (pupopTabsType === '1') {
                    if (columnName === 'bill_edit_num') {
                        queryDataText = '填制人 等于 ' + rowData.name;
                        paramsQueryDataText = `and (Isnull(TZR,'')='${rowData.name}')`;
                    } else if (columnName === 'bill_carryto_num') {
                        queryDataText = '过账人 等于 ' + rowData.name;
                        paramsQueryDataText = `and (Isnull(SHR,'')='${rowData.name}')`;
                    } else if (columnName === 'bill_check_num') {
                        queryDataText = '审核人 等于 ' + rowData.name;
                        paramsQueryDataText = `and (Isnull(JZR,'')='${rowData.name}')`;
                    } else {
                        queryDataText = '操作用户 等于 ' + rowData.name;
                        paramsQueryDataText = `and ( Isnull(TZR,'')='${rowData.name}' or Isnull(SHR,'')='${rowData.name}' or Isnull(JZR,'')='${rowData.name}')`;
                    }
                } else {
                    queryDataText = `(填制人 等于 ${rowData?.TZR ?? '空'})并且(过账人 等于 ${rowData?.SHR ?? '空'})并且(审核人 等于 ${rowData?.JZR ?? '空'})`;
                    paramsQueryDataText = `and ( Isnull(TZR,'')='${rowData?.TZR ?? ' '}' and Isnull(SHR,'')='${rowData?.SHR ?? ' '}' and Isnull(JZR,'')='${rowData?.JZR ?? ' '}')`;
                }
            } else {
                queryDataText = '科目名称 等于 ' + rowData.KMMC;
                paramsQueryDataText = `and (KMBH = '${rowData.KMBH}')`;
            }
            setQueryData(queryDataText);
            setparamsQueryData(paramsQueryDataText);
            await searchFunction({ yearID, checkQueryContent: true }, paramsQueryDataText);
            setSearchParams({
                yearID,
                checkQueryContent: true,
                xswzpzCheck: false,
                jefsID: 0,
                PZCYStart: '',
                PZCYEnd: '',
                jeStart: '',
                jeEnd: '',
                kmmcStr: '',
                dfkmmcStr: '',
                zyStr: '',
            });
            setVisible(true);
        },
    }));

    const sqlTextFun = (itemVal: any) => {
        let andorStrSql: string = '';
        let leftParenthesisSql: string = '';
        let StateIDSql: string = '';
        let rightParenthesisSql: string = '';
        const { andorStr, leftParenthesis, conditionsName, StateID, rowConditionsData, rightParenthesis } = itemVal;

        if (andorStr === '0') {
            andorStrSql = 'or';
        } else {
            andorStrSql = 'and';
        }
        if (leftParenthesis === '1') {
            leftParenthesisSql = '（';
        } else {
            leftParenthesisSql = '';
        }
        StateIDSql = conditionStatesData[StateID].conditionName;
        if (rightParenthesis === '1') {
            rightParenthesisSql = '）';
        } else {
            rightParenthesisSql = '';
        }
        return `${andorStrSql}（${leftParenthesisSql && rightParenthesisSql ? leftParenthesisSql : ''}${conditionsName}
         ${StateIDSql} 
        ${rowConditionsData}${leftParenthesisSql && rightParenthesisSql ? rightParenthesisSql : ''}）`;
    }

    const sqlStrFun = (itemVal: any) => {
        let andorStrSql: string = '';
        let leftParenthesisSql: string = '';
        let StateIDSql: string = '';
        let rightParenthesisSql: string = '';
        let rowDataStrSql: string = '';

        const { andorStr, leftParenthesis, StateID, rowConditionsData, rightParenthesis, keyString, sqlType } = itemVal;

        let isNullSql: string | number = sqlType === 'string' ? `' '` : 0;
        if (andorStr === '0') {
            andorStrSql = 'or';
        } else {
            andorStrSql = 'and';
        }
        if (leftParenthesis === '1') {
            leftParenthesisSql = '(';
        } else {
            leftParenthesisSql = '';
        }
        StateIDSql = conditionStatesData[StateID].slqfh;
        if (StateID === 7 || StateID === 8) {
            rowDataStrSql = `'%${rowConditionsData}%'`;
        } else if (StateID === 9) {
            rowDataStrSql = `'${rowConditionsData}%'`;
        } else if (StateID === 10) {
            rowDataStrSql = `'%${rowConditionsData}'`;
        } else if (StateID === 11 || StateID === 12) {
            rowDataStrSql = `''`;
        } else if (StateID === 13) {
            rowDataStrSql = `Len(IsNull(${keyString}, ${isNullSql})) = ${rowConditionsData}`;
        } else {
            rowDataStrSql = `'${rowConditionsData}'`;
        }
        if (rightParenthesis === '1') {
            rightParenthesisSql = ')';
        } else {
            rightParenthesisSql = '';
        }

        if (keyString === 'FSE') {
            let FSEDataStrSql = 'IsNull((IsNull(JFJE,0) + IsNull(DFJE,0)),0)';
            if (StateID === 13) {
                FSEDataStrSql = `Len(IsNull((IsNull(JFJE,0) + IsNull(DFJE,0)),0)) = ${rowConditionsData}`;
                return `${andorStrSql} (${leftParenthesisSql && rightParenthesisSql ? leftParenthesisSql : ''} ${FSEDataStrSql} ${leftParenthesisSql && rightParenthesisSql ? rightParenthesisSql : ''})`;
            }
            return `${andorStrSql} (${leftParenthesisSql && rightParenthesisSql ? leftParenthesisSql : ''} ${FSEDataStrSql} ${StateIDSql} ${rowDataStrSql} ${leftParenthesisSql && rightParenthesisSql ? rightParenthesisSql : ''})`;
        }
        if (StateID === 13) {
            return `${andorStrSql} (${leftParenthesisSql && rightParenthesisSql ? leftParenthesisSql : ''} ${rowDataStrSql} ${leftParenthesisSql && rightParenthesisSql ? rightParenthesisSql : ''})`;
        }
        return `${andorStrSql} (${leftParenthesisSql && rightParenthesisSql ? leftParenthesisSql : ''} IsNull(${keyString}, ${isNullSql}) ${StateIDSql} ${rowDataStrSql} ${leftParenthesisSql && rightParenthesisSql ? rightParenthesisSql : ''})`;
    }
    const createSqlText = (sqlData: any[]) => {
        let sqlTextArr: string[] = [];
        let sqlStrArr: string[] = [];

        sqlData.forEach(item => {
            sqlTextArr.push(sqlTextFun(item));
        });

        sqlData.forEach(item => {
            sqlStrArr.push(sqlStrFun(item));
        });
        setQueryData(sqlTextArr.join(' '));
        setparamsQueryData(sqlStrArr.join(' '));

    }

    return (
        <>
            <Popup
                ref={popupRef}
                visible={visible}
                title={pupopTitleText}
                width={'80vw'}
                height={'90vh'}

                // dragOutsideBoundary={true}
                // resizeEnabled={true}
                onHiding={() => { onCancel() }}
            >
                <div className={`certificateListPupopBox ${openPpupopType === '1' ? 'certificateListPupop1' : 'certificateListPupop2'} certificateListPupopBox130`}>
                    <div className="search-tool-containerPupopBox">
                        <div style={{ width: 'calc(100% - 5px)', height: 40, display: 'flex' }}>
                            <DevToolBar.Default>
                                <Item location={"before"} locateInMenu={'auto'}>
                                    <div className={'itemBoxGroup'}>
                                        <div className="itemBoxDispalyPupopBox-kjfl" style={{ marginBottom: '8px' }}>
                                            <div style={{
                                                width: '45px',
                                                padding: '0 5px'
                                            }}>
                                                金额:
                                            </div>
                                            <div
                                                className="itemBoxDispalyPupopBox-kjfl"
                                                style={{ width: 290, justifyContent: 'space-between' }}
                                            >
                                                <NumberBox
                                                    width={120}
                                                    format="#,##0.##"
                                                    min={0}
                                                    // valueChangeEvent='keyup'
                                                    value={searchParams.jeStart}
                                                    onValueChange={(value: any) => {
                                                        console.log(value, '@@@');
                                                        const tempVal = value === 0 ? '' : value;

                                                        changeData('jeStart', tempVal);
                                                    }}
                                                />
                                                <div style={{
                                                    width: '30px',
                                                    textAlign: 'center'
                                                }}>
                                                    至
                                                </div>
                                                <NumberBox
                                                    width={120}
                                                    min={0}
                                                    format="#,##0.##"
                                                    // valueChangeEvent='keyup'
                                                    value={searchParams.jeEnd}
                                                    onValueChange={(value: any) => {
                                                        console.log(value, '@@@');
                                                        const tempVal = value === 0 ? '' : value;
                                                        changeData('jeEnd', tempVal);
                                                    }}
                                                />
                                            </div>
                                        </div>
                                    </div>
                                </Item>
                                <Item location={"before"} locateInMenu={'auto'}>
                                    <div className={'itemBoxGroup'}>
                                        <div className="itemBoxDispalyPupopBox-kjfl" style={{ marginBottom: '8px' }}>

                                            <div style={{
                                                width: '70px',
                                                padding: '0 5px'
                                            }}>
                                                科目名称:
                                            </div>
                                            <TextBox
                                                value={searchParams.kmmcStr}
                                                width={150}
                                                // valueChangeEvent='keyup'
                                                onValueChange={(value: any) => {
                                                    changeData('kmmcStr', value);
                                                }}
                                            // inputAttr={nameLabel}
                                            >
                                                <TextBoxButton
                                                    name="text"
                                                    location="after"
                                                    options={{
                                                        icon: "more",
                                                        stylingMode: "text",
                                                        onClick: () => {
                                                            console.log("@@@ text 刷新");

                                                            SubjectRef.current.show({
                                                                title: "选择科目",
                                                                dbname: dbname,
                                                                Data_ID: searchParams.yearID,
                                                                isHasFZZ: false,
                                                                editUser: username,
                                                                // 选择 模式 0：单选 1：多选连机选择
                                                                selectMode: '1',
                                                                //  1：多选连机选择时是否进行递归选择默认是 true
                                                                recursiveMultiple: false,
                                                                // 是否为辅助账 
                                                                auxiliaryState: false,
                                                                // 可以选择当前节点的科目
                                                                isSelectSuperior: false,
                                                                // 自动结转科目 默认选中的类型参数
                                                                subjectType: "periodEarly",
                                                                okCallback: (r: any, v: any) => {
                                                                    console.log(r, v, '@@@ r, v');

                                                                    // 科目审定明细 界面增加一级科目在业务组件 需做更改
                                                                    let kmmcData = '';
                                                                    if (v.length > 1) {
                                                                        kmmcData = v.map((item: any) => item.KMMC).join(',');
                                                                    } else {
                                                                        kmmcData = r.KMMC;
                                                                    }

                                                                    changeData('kmmcStr', kmmcData);
                                                                },
                                                            });
                                                        }
                                                    }}
                                                />
                                            </TextBox>
                                        </div>
                                    </div>
                                </Item>
                                <Item location={"before"} locateInMenu={'auto'}>
                                    <div className={'itemBoxGroup'}>
                                        <div className="itemBoxDispalyPupopBox-kjfl" style={{ marginBottom: '8px' }}>
                                            <div style={{
                                                width: '70px',
                                                padding: '0 5px'
                                            }}>
                                                对方科目:
                                            </div>
                                            <TextBox
                                                value={searchParams.dfkmmcStr}
                                                width={150}
                                                onValueChange={(value: any) => {
                                                    changeData('dfkmmcStr', value);
                                                }}
                                            // valueChangeEvent='keyup'
                                            // inputAttr={nameLabel}
                                            >
                                                <TextBoxButton
                                                    name="text"
                                                    location="after"
                                                    options={{
                                                        icon: "more",
                                                        stylingMode: "text",
                                                        onClick: () => {
                                                            console.log("@@@ text 刷新");

                                                            SubjectRef.current.show({
                                                                title: "选择科目",
                                                                dbname: dbname,
                                                                Data_ID: searchParams.yearID,
                                                                isHasFZZ: false,
                                                                editUser: username,
                                                                // 选择 模式 0：单选 1：多选连机选择
                                                                selectMode: '1',
                                                                //  1：多选连机选择时是否进行递归选择默认是 true
                                                                recursiveMultiple: false,
                                                                // 是否为辅助账 
                                                                auxiliaryState: false,
                                                                // 可以选择当前节点的科目
                                                                isSelectSuperior: false,
                                                                // 自动结转科目 默认选中的类型参数
                                                                subjectType: "periodEarly",
                                                                okCallback: (r: any, v: any) => {
                                                                    // 科目审定明细 界面增加一级科目在业务组件 需做更改
                                                                    let kmmcData = '';
                                                                    if (v.length > 1) {
                                                                        kmmcData = v.map((item: any) => item.KMMC).join(',');
                                                                    } else {
                                                                        kmmcData = r.KMMC;
                                                                    }

                                                                    changeData('dfkmmcStr', kmmcData);
                                                                },
                                                            });
                                                        }
                                                    }}
                                                />
                                            </TextBox>
                                        </div>
                                    </div>
                                </Item>
                                <Item location={"before"} locateInMenu={'auto'}>
                                    <div className={'itemBoxGroup'}>
                                        <div className="itemBoxDispalyPupopBox-kjfl" style={{ marginBottom: '8px' }}>
                                            <div
                                                style={{
                                                    width: '60px',
                                                    display: 'flex',
                                                    justifyContent: 'space-between',
                                                    alignItems: 'center',
                                                    margin: '0 5px',
                                                }}
                                            >
                                                <span>摘</span>
                                                <span>要:</span>

                                            </div>
                                            <TextBox
                                                width={120}
                                                value={searchParams.zyStr}
                                                onValueChange={(value: any) => {
                                                    console.log(value, '@@@');
                                                    changeData('zyStr', value);
                                                }}
                                            />
                                        </div>
                                    </div>
                                </Item>

                                {openPpupopType === '1' && <Item location={"before"} locateInMenu={'auto'}>
                                    <div className={'itemBoxGroup'}>
                                        <div className="itemBoxDispalyPupopBox-kjfl" style={{ marginBottom: '8px' }}>
                                            <div style={{
                                                width: '70px',
                                                padding: '0 5px'
                                            }}>
                                                凭证差异:
                                            </div>
                                            <NumberBox
                                                width={120}
                                                min={0}
                                                format="#,##0.##"
                                                // valueChangeEvent='keyup'
                                                value={searchParams.PZCYStart}
                                                onValueChange={(value: any) => {
                                                    console.log(value, '@@@');
                                                    const tempVal = value === 0 ? '' : value;
                                                    changeData('PZCYStart', tempVal);
                                                }}
                                            />
                                            <div style={{
                                                width: '30px',
                                                textAlign: 'center'
                                            }}>
                                                至
                                            </div>
                                            <NumberBox
                                                width={120}
                                                min={0}
                                                format="#,##0.##"
                                                // valueChangeEvent='keyup'
                                                value={searchParams.PZCYEnd}
                                                onValueChange={(value: any) => {
                                                    console.log(value, '@@@');
                                                    const tempVal = value === 0 ? '' : value;
                                                    changeData('PZCYEnd', tempVal);
                                                }}
                                            />
                                        </div>
                                    </div>
                                </Item>}

                            </DevToolBar.Default>
                            <div className={'itemBoxGroup'}>
                                <div className="itemBoxDispalyPupopBox-kjfl">
                                    <Button
                                        text="查询"
                                        type='default'
                                        onClick={() => {
                                            // console.log(searchParams, paramsQueryData, '@@@ searchParams');
                                            searchFunction(searchParams, paramsQueryData);

                                        }} />
                                    <Button
                                        type='default'
                                        hint='查询条件清理'
                                        onClick={() => {
                                            setSearchParams((oldObj: any) => {
                                                let newObj = { ...oldObj };
                                                newObj = {
                                                    ...newObj,
                                                    PZCYStart: '',
                                                    PZCYEnd: '',
                                                    jeStart: '',
                                                    jeEnd: '',
                                                    kmmcStr: '',
                                                    dfkmmcStr: '',
                                                    zyStr: '',
                                                }
                                                return newObj
                                            })
                                            notify(`已清理查询条件！`, "success", 2000);
                                        }} >
                                        <ClearOutlined />
                                    </Button>
                                    {openPpupopType === '2' &&
                                        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                                            <div style={{
                                                padding: '0 5px',
                                                width: '80px',
                                            }}>
                                                显示格式：
                                            </div>
                                            <SelectBox
                                                width="130"
                                                placeholder=''
                                                dataSource={[
                                                    { id: 0, name: '金额式' },
                                                    { id: 1, name: '数量金额式' },
                                                    { id: 2, name: '数量外币式' },
                                                    { id: 3, name: '外币金额式' },
                                                ]}
                                                dropDownOptions={{
                                                    width: '120px'
                                                }}
                                                displayExpr="name"
                                                valueExpr="id"
                                                value={searchParams.jefsID}
                                                onValueChanged={(e: any) => {
                                                    console.log(e.value, '@@@ e.value');
                                                    changeData('jefsID', e.value);
                                                }} />
                                            <div style={{
                                                width: '10px',
                                                height: '10px'
                                            }}>

                                            </div>
                                            <CheckBox
                                                width={'110'}
                                                text="显示完整凭证"
                                                value={searchParams.xswzpzCheck}
                                                onValueChanged={(e: any) => {
                                                    changeData('xswzpzCheck', e.value, 'query');
                                                }}
                                            />
                                        </div>}
                                </div>
                            </div>
                        </div>
                    </div>


                    <div className={'search-tool-containerPupopBox-place'} />
                    <div className="contentSearchBoxTS">
                        <div style={{
                            display: "flex",
                            alignItems: 'center',
                            justifyContent: 'left',
                            width: 'calc(100% - 35px)',
                        }}>
                            <div>
                                <CheckBox
                                    value={searchParams.checkQueryContent}
                                    onValueChanged={(e: any) => {
                                        console.log(e.value, '@@@ e.value');
                                        changeData('checkQueryContent', e.value, 'query');
                                    }}
                                />
                            </div>

                            <div style={{
                                width: 'calc(100% - 25px)',
                                paddingLeft: '8px',
                            }}>

                                <Text style={{ width: '100%', color: `${searchParams.checkQueryContent ? '#000' : '#999'}` }} ellipsis={{ tooltip: queryData }}>
                                    {queryData}
                                </Text>

                            </div>

                        </div>
                        <Button
                            icon='iconfont icon-ellipsis'
                            className='refreshButton_Style'
                            onClick={() => {
                                advancedQueryPupopRef.current.showAdvancedQueryPupop({
                                    okCallback: (okData: any[]) => {
                                        // setCheckContent(true);
                                        changeData('checkQueryContent', true);

                                        if (okData.length > 0) {
                                            createSqlText(okData);
                                        } else {
                                            setparamsQueryData('');
                                        }
                                    }
                                });
                            }} />

                    </div>
                    {useMemo(() => {
                        let realCol: any = [];
                        if (openPpupopType === '1') {
                            realCol = [...columnsDataMQW];
                        } else {
                            if (searchParams.jefsID === 0) {
                                realCol = [...columnsDataMQW2];
                            } else if (searchParams.jefsID === 1) {
                                realCol = [...columnsDataMQW2_1];
                            } else if (searchParams.jefsID === 2) {
                                realCol = [...columnsDataMQW2_2];
                            } else if (searchParams.jefsID === 3) {
                                realCol = [...columnsDataMQW2_3];
                            }
                        }
                        return <DevGrid.RangeTap
                            className={` PaperDevSortableGrid devHeadersCenter `}
                            height={'calc(100% - 90px)'}
                            width="100%"
                            key={changeKey}
                            ref={devGridRef}
                            dataSource={dataGridData}
                            keyExpr={openPpupopType === '1' ? 'PZID' : 'FLID'}
                            columns={realCol}
                            showBorders={true}
                            showRowLines={true}
                            showColumnLines={true}
                            allowColumnResizing={true}
                            searchPanel={{
                                visible: false,
                                width: 180,
                                placeholder: '',
                            }}
                            paging={{
                                enabled: false,
                            }}

                            onCellDblClick={(e) => {
                                const { rowType, data, column } = e;
                                if (rowType === 'data') {
                                    let tmepRowData = [{ ...data, Data_ID: searchParams.yearID, dbname }];
                                    accountingVoucherPupopRef.current.showPupop({ ...data, Data_ID: searchParams.yearID, dbname }, tmepRowData);
                                    // console.log(e, data, column.dataField);
                                    // if (treeSelectKey === '0-0-0-1' || treeSelectKey === '0-0-0-0') {
                                    //     certificateListPupopRef.current.showPupop({
                                    //         rowData: data,
                                    //         yearID,
                                    //         columnName: column.dataField,
                                    //         pupopType: treeSelectKey === '0-0-0-1' ? '2' : '1',
                                    //         changeNodeKey: treeSelectKey,
                                    //         pupopTabsType: changeTab,
                                    //     });
                                    // } else if (treeSelectKey === '0-0-0') {
                                    //     if (changeTab === '1') {
                                    //         certificateListPupopRef.current.showPupop({
                                    //             rowData: data,
                                    //             yearID,
                                    //             columnName: column.dataField,
                                    //             pupopType: '1',
                                    //             changeNodeKey: treeSelectKey,
                                    //             pupopTabsType: changeTab,
                                    //         });
                                    //     } else {
                                    //         msgInfo(`正在打开 其他会计分录测试模型,请稍候...`);
                                    //         // UserCode={1} UserPwd={c4ca4238a0b923820dcc509a6f75849b} ProjectCode={202202-AUD-2020-001} ZcbfID={202202-AUD-2020-001}
                                    //         if (window.electronComponents) {
                                    //             const sessionParams = JSON.parse(window.sessionStorage.electronParams);
                                    //             const { sjxmbh, ZcbfID } = sessionParams.params;
                                    //             window.location.href = `cpas://OpenLocalFile/?fileName={UFCPAS4_PATH}/UFCPAS4.exe&params=UserCode={UserCode} UserPwd={UserPwd} ProjectCode=${sjxmbh} ZcbfID=${ZcbfID} Functions=RIM_110 FunParameters="Data_ID=${yearID},KMBH=${data.KMBH}"`;
                                    //         } else {
                                    //             console.error("window[\"electronComponents\"] false")
                                    //         }
                                    //     }
                                    // } else if (treeSelectKey === '0-0-1') {
                                    //     let tmepRowData = [{ ...data, Data_ID: yearID, dbname }];
                                    //     if (data.gap > 0) {
                                    //         tmepRowData = [...tmepRowData, {
                                    //             PZBH: data.PZBH_Prior_Org,
                                    //             PZLX: data.PZLX_Prior_Org,
                                    //             PZRQ: data.PZRQ_Prior_Org,
                                    //             Data_ID: yearID, dbname
                                    //         }];
                                    //     };
                                    //     accountingVoucherPupopRef.current.showPupop({ ...data, Data_ID: yearID, dbname }, tmepRowData);
                                    // }
                                }


                            }}
                            loadPanel={{ enabled: true }}
                            scrolling={{
                                mode: "virtual",
                                rowRenderingMode: "virtual",
                                renderAsync: true
                            }}
                        >

                            <Summary>
                                {openPpupopType === '1' ? <TotalItem
                                    column="PZRQ"
                                    // summaryType="text"
                                    customizeText={(itemInfo: any) => {
                                        return `    合计：`;
                                    }}
                                /> : <TotalItem
                                    column="KMMC"
                                    // summaryType="text"
                                    customizeText={(itemInfo: any) => {
                                        return `    合计：`;
                                    }}
                                />}
                                {openPpupopType === '1' && <TotalItem
                                    column="PZLX"
                                    customizeText={(itemInfo: any) => {
                                        return `单据数量：${itemInfo.value}`;
                                    }}
                                />}

                                {/* searchParams.jefsID */}

                                {searchParams.jefsID !== 2 && <TotalItem
                                    column="JFJE"
                                    summaryType="sum"
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                                {searchParams.jefsID !== 2 && <TotalItem
                                    column="DFJE"
                                    summaryType="sum"
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                                {(searchParams.jefsID === 1 || searchParams.jefsID === 2) && <TotalItem
                                    column="JFSL"
                                    summaryType="sum"
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                                {(searchParams.jefsID === 1 || searchParams.jefsID === 2) && <TotalItem
                                    column="DFSL"
                                    summaryType="sum"
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                                {(searchParams.jefsID === 3 || searchParams.jefsID === 2) && <TotalItem
                                    column="JFWB"
                                    summaryType="sum"
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                                {(searchParams.jefsID === 3 || searchParams.jefsID === 2) && <TotalItem
                                    column="DFWB"
                                    summaryType="sum"
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                                {openPpupopType === '1' && <TotalItem
                                    column="Diff"
                                    summaryType="sum"
                                    alignment={"right"}
                                    customizeText={(itemInfo: any) => {
                                        return moneyFormatCol(itemInfo.value);
                                    }}
                                />}
                            </Summary>
                        </DevGrid.RangeTap>

                    }, [openPpupopType, dataGridData, searchParams])}



                </div>
            </Popup >
            <AdvancedQueryPupop ref={advancedQueryPupopRef} />
            <SubjectPopup ref={SubjectRef} />
            <AccountingVoucherPupop ref={accountingVoucherPupopRef}
                cellDblClickCallback={(rowData: any, curYear: any) => {
                    msgInfo(`正在打开 明细账,请稍候...`);
                    if (window.electronComponents) {
                        const sessionParams = JSON.parse(window.sessionStorage.electronParams);
                        const { sjxmbh, ZcbfID } = sessionParams.params;
                        window.location.href = `cpas://OpenLocalFile/?fileName={UFCPAS4_PATH}/UFCPAS4.exe&params=UserCode={UserCode} UserPwd={UserPwd} ProjectCode=${sjxmbh} ZcbfID=${ZcbfID} Functions=FM_103 FunParameters="Data_ID=${curYear},KMBH=${rowData.KMBH}"`;
                    } else {
                        console.error('window["electronComponents"] false');
                    }
                }}
            />
        </>
    );
});

export default CertificateListPupop;
